package com.ruoyi.receivable.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receivable.domain.ErpAccountReceivable;
import com.ruoyi.receivable.service.IErpAccountReceivableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应收款明细Controller
 * 
 * @author ruoyi
 * @date 2025-07-19
 */
@RestController
@RequestMapping("/receivable/receivable")
public class ErpAccountReceivableController extends BaseController
{
    @Autowired
    private IErpAccountReceivableService erpAccountReceivableService;

    /**
     * 查询应收款明细列表
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpAccountReceivable erpAccountReceivable)
    {
        startPage();
        List<ErpAccountReceivable> list = erpAccountReceivableService.selectErpAccountReceivableList(erpAccountReceivable);
        return getDataTable(list);
    }

    /**
     * 导出应收款明细列表
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:export')")
    @Log(title = "应收款明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpAccountReceivable erpAccountReceivable)
    {
        List<ErpAccountReceivable> list = erpAccountReceivableService.selectErpAccountReceivableList(erpAccountReceivable);
        ExcelUtil<ErpAccountReceivable> util = new ExcelUtil<ErpAccountReceivable>(ErpAccountReceivable.class);
        util.exportExcel(response, list, "应收款明细数据");
    }

    /**
     * 获取应收款明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:query')")
    @GetMapping(value = "/{outboundNo}")
    public AjaxResult getInfo(@PathVariable("outboundNo") String outboundNo)
    {
        return success(erpAccountReceivableService.selectErpAccountReceivableByOutboundNo(outboundNo));
    }

    /**
     * 新增应收款明细
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:add')")
    @Log(title = "应收款明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpAccountReceivable erpAccountReceivable)
    {
        return toAjax(erpAccountReceivableService.insertErpAccountReceivable(erpAccountReceivable));
    }

    /**
     * 修改应收款明细
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:edit')")
    @Log(title = "应收款明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpAccountReceivable erpAccountReceivable)
    {
        return toAjax(erpAccountReceivableService.updateErpAccountReceivable(erpAccountReceivable));
    }

    /**
     * 删除应收款明细
     */
    @PreAuthorize("@ss.hasPermi('receivable:receivable:remove')")
    @Log(title = "应收款明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outboundNos}")
    public AjaxResult remove(@PathVariable String[] outboundNos)
    {
        return toAjax(erpAccountReceivableService.deleteErpAccountReceivableByOutboundNos(outboundNos));
    }
}
